package com.example.administrator.kaohedemo.Store;

import com.example.administrator.kaohedemo.Action.Action;
import com.example.administrator.kaohedemo.Action.Actions;
import com.example.administrator.kaohedemo.Model.CourseListBean;
import com.example.administrator.kaohedemo.Model.SeeClassRecordAdapterBean;
import com.example.administrator.kaohedemo.Model.SeeClassRecordBean;
import com.google.gson.Gson;
import com.squareup.otto.Subscribe;

/**
 * Created by Administrator on 2016/6/24.
 */
public class SeeClassRecordStore extends Store {

    private static SeeClassRecordStore seeClassRecordStore;
    private SeeClassRecordStoreChanged seeClassRecordStoreChanged;


    public static SeeClassRecordStore getInstense(){
        if (seeClassRecordStore==null){
            seeClassRecordStore=new SeeClassRecordStore();
        }
        return seeClassRecordStore;
    }

    @Override
    @Subscribe
    public void onAction(Action action) {
        GetSeeClassRecordStoreChanged();
        String type=action.getType();
        switch (type){
            case Actions.CourseListActions.TYPE_HTTP_RESULT:
                seeClassRecordStoreChanged.setType(type);
                Gson gson=new Gson();
                String result=(String) action.getMap().get(Actions.SeeClassRecordActivity.KEY_HTTP_RESULT);
                SeeClassRecordBean bean=gson.fromJson(result,SeeClassRecordBean.class);
                seeClassRecordStoreChanged.setBean(bean);
                UIChanged();
                break;
            case Actions.SeeClassRecordActivity.TYPE_RECORD_CLICK:
                seeClassRecordStoreChanged.setType(type);
                SeeClassRecordAdapterBean adapterbean= (SeeClassRecordAdapterBean) action.getMap().get(Actions.SeeClassRecordActivity.KEY_RECORD_CLICK);
                seeClassRecordStoreChanged.setAdapterbean(adapterbean);
                UIChanged();
                break;
        }
    }

    private void GetSeeClassRecordStoreChanged() {
        if (seeClassRecordStoreChanged==null){
            seeClassRecordStoreChanged=new SeeClassRecordStoreChanged();
        }
    }

    @Override
    protected StoreChanged changed() {
        return seeClassRecordStoreChanged;
    }

    public class SeeClassRecordStoreChanged implements StoreChanged{

        String type;
        int position;
        SeeClassRecordBean bean;
        SeeClassRecordAdapterBean adapterbean;

        public SeeClassRecordAdapterBean getAdapterbean() {
            return adapterbean;
        }

        public void setAdapterbean(SeeClassRecordAdapterBean adapterbean) {
            this.adapterbean = adapterbean;
        }

        public String getType() {
            return type;
        }

        public void setType(String type) {
            this.type = type;
        }

        public SeeClassRecordBean getBean() {
            return bean;
        }

        public void setBean(SeeClassRecordBean bean) {
            this.bean = bean;
        }

        public int getPosition() {
            return position;
        }

        public void setPosition(int position) {
            this.position = position;
        }
    }
}
